package top.drinyeit.weilong.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import top.drinyeit.weilong.R;
import top.drinyeit.weilong.base.BaseActivity;
import top.drinyeit.weilong.presenter.BalancePresenter;

/**
 * Created by bigHead on 2017/11/21.
 * last update on 18/3/21
 */

public class BalanceActivity extends BaseActivity {
    public TextView balance, balance_detail;
    private RelativeLayout recharge, withdraw;
    public double balanceNumber;

    private BalancePresenter balancePresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_balance);

        balance_detail = findViewById(R.id.balance_detail);
        balance = findViewById(R.id.tv_balance);
        recharge = findViewById(R.id.rl_recharge);
        withdraw = findViewById(R.id.rl_withdraw);

        initDate();
        init();
        setTitle(true, "余额");
    }

    private void initDate() {
        balancePresenter = new BalancePresenter(this);
        balancePresenter.getBalance();
    }

    @Override
    public void init() {
        balance_detail.setVisibility(View.VISIBLE);
        balance_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(BalanceActivity.this, PaymentDetailsActivity.class);
                startActivity(intent);
            }
        });
        //充值
        recharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(BalanceActivity.this, RechargeActivity.class), 1);
            }
        });
        //提现
        withdraw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(BalanceActivity.this, WithdrawActivity.class);
                intent.putExtra("balance", balanceNumber);
                startActivityForResult(intent, 1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == 1) {
            initDate();
        }
    }
}
